package com.atguigu.java.ai.langchain4j.tools;


import com.atguigu.java.ai.langchain4j.entity.Appointment;
import com.atguigu.java.ai.langchain4j.service.AppointmentService;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AppointmentTools {

    @Autowired
    private AppointmentService appointmentService;


    @Tool(name = "bookAppointment",value = "根据参数，先执行工具方法queryAppointment查询是否可预约，并直接给用户回答是否可预约，并让用户确认所有预约信息，用户确认后再进行预约。如果没有提供具体医生姓名，请从向量存储中找到一位医生。")
    public String bookAppointment(Appointment appointment){
        Appointment appointmentDB = appointmentService.getOne(appointment);
        if (appointmentDB == null){
            appointment.setId(null);//防止大模型随机创建ID
            if (appointmentService.save(appointment)){
                return "预约成功";
            }
            return "预约失败";
        }
        return "预约失败，该时间段已被预约";
    }

    @Tool(name = "cancelAppointment",value = "根据参数，查询预约是否存在 如果存在删除预约记录并返回取消预约成功,否则返回取消预约失败")
    public String cancelAppointment(Appointment appointment){
        Appointment appointmentDB = appointmentService.getOne(appointment);
        if (appointmentDB != null){
            if (appointmentService.removeById(appointmentDB)){
                return "取消预约成功";
            }
            return "取消预约失败";
        }
        return "取消预约失败，该时间段未被预约";
    }

    @Tool(name = "queryAppointment",value = "根据科室、日期、时间查询与医生名称查询是否有号源，返回预约情况")
    public Boolean queryAppointment(
            @P(value = "科室名称") String department,
            @P(value = "预约日期") String date,
            @P(value = "预约时间 可选择值:间隔一个小时的时间范围") String time,
            @P(value = "医生名称",required = false) String doctorName
    ){
        return true;
    }

}
